@extends('backend/layouts/default')
@section('title')
Danh sách Blog
@stop
@section('content')
<h3>
    <span class="glyphicon glyphicon-pencil"></span> Danh sách câu hỏi
<!--    <a href="" data-toggle="modal" data-target="#modal_newpost" class="btn btn-default btn-xs"><span
            class="glyphicon glyphicon-plus-sign"></span> Hợp âm mới</a>-->
</h3>
<div class="box">
    <div class="box-header">
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <div class="row">
            <div class="col-ld-2 col-md-3 col-sm-3">
                <ul class="nav nav-pills nav-stacked">
                    <li >
                        <a href="#"><span class="glyphicon glyphicon-th-list"></span>
                            Tất cả
                        </a>
                    </li>
               
               
                </ul>
            </div>
            <div class="col-ld-10 col-md-9 col-sm-9">
                <form method="get" action="" autocomplete="off" role="form" class="form-inline">
                    <input type="hidden" name="_token" value=""/>

                    <div class="form-group">

                    </div>
                    <div class="form-group">
                        <?= Form::select('category', array('-1' => "Chọn chuyên mục", '0' => "Không thuộc chuyên mục nào") + $data['categories'], Input::old('category', $data['appends']['category']), array('class' => 'form-control')); ?>
                    </div>
                    <input type="submit" class="btn btn-default btn-info" name="search" value="Tìm"/>
                </form>
                <hr/>

                <table  style="width: 85% "id="mytable" class="table table-bordred table-striped">

                    <thead>
                        <tr>
                            <th width="60"></th>
                            <th width="450">Tiêu đề</th>
                            <th width="200">Chuyên mục</th>
                            <th width="150">Ngày</th>
                            <th width="150">Tác vụ</th>
                            <th width="100" style="text-align: center">Tiêu biểu</th>
                        </tr>
                    </thead>
                    <tbody>

                        @foreach($data['questions'] as $question)
                        <tr>
                            <td>{{$question->id}}</td>
                            <td>{{$question->title}}</td>
                            <td><?= $question->category_id > 0 ? $question->category_title : "Chưa có chuyên mục" ?></td>
                            <td>{{$question->created_at->diffForHumans()}}</td>
                            <td>    
                                <a href="{{route('edit/question',$question->id)}}" class="btn btn-mini btn-default">@lang('button.edit')</a>                             
                                <a href="{{route('delete/question',$question->id)}}" class="btn btn-mini btn-danger">@lang('button.delete')</a>                             
                            </td>
                            <td class="addcheck_hot{{$question->id}}" style="text-align: center"><input id="check_hot" value ="{{$question->id}}" style="text-align: center" type="checkbox" class="checkbox-inline" {{$question->is_hot == 0 ? ""  : "checked"}}/></td>
                        </tr>
                        @endforeach()
                    </tbody>

                </table>

                <div class="clearfix"></div>
                {{ $data['questions']->links() }}


                <script>
                    function show_confirm(obj) {
                        var r = confirm("Bạn có thực sự muốn xóa?");
                        if (r == true)
                            window.location = obj.attr('href');
                    }
                    $('a.btn-danger').click(function (event) {
                        event.preventDefault();
                        show_confirm($(this));
                    });
                    /*Xử lý checked*/
                    function saveHot(id) {
                        $.ajax({
                            type: 'post',
                            url: '<?= route('questions') ?>/checkquestion?save_hot=' + id,
                            dataType: 'html',
                        }).done(function (data) {
                            $('.addcheck_hot' + id).html(data);
                            // location.hash = page;

                        }).fail(function () {
                            alert('Posts could not be loaded.');
                        });
                    }
                    $(document).on('click', '#check_hot', function (e) {
                        saveHot($(this).attr('value'));
                        e.preventDefault();
                    });
                </script>

            </div>
        </div>
    </div>
</div>
@stop